*** One-Child Policy, Marriage Distortion, and Welfare Loss ***
*** by Wei Huang, Yinghao Pan and Yi Zhou ***

clear all 
set more off
cap log close 

set niceness 10
gl MAIN = "F:\Dropbox"

gl path1 = "$MAIN/Census"
gl path2 = "$MAIN/Marriage/Working_data"
gl path3 = "$MAIN/Marriage/Restat/dataverse_files/Results" 
gl path4 = "$MAIN/Marriage/Restat/dataverse_files/Graphics" 



use "$path2/unmarried", clear
keep if relation == 0 | relation == 1 | relation == 2 | relation == 6 

merge 1:1 wave area hhid name relation using "$path2/min_marr_policy", keepusing(marry_1 marry_2 marry_3)


drop if mi(hktype)
replace urban = hktype == 1 
su age 

cap gen female = 1-male
cap gen han = 1- minority 

replace unmarried = unmarried * 100 
gen unmarr_25 = marr_age > 25 if !mi(marr_age)
replace unmarr_25 = 1 if unmarried == 100 
replace unmarr_25 = unmarr_25 *100 

gen urban_hk = hktype == 2 

egen clsid = group(prov_hk year_birth)

gen marry_9 = unmarried == 0 & (mi(marry_1) & mi(marry_2) & mi( marry_3))

recode marry_1 marry_2 marry_3 (. = 0) 

gen HH = marry_1 * 100 
gen HM = marry_2 * 100 
gen MM = marry_3 * 100 
gen Other = marry_9 * 100 
gen HOMO = HH + MM
su HOMO

keep if age <= 55 
keep if age > 25
keep if year_birth <= 1980 
keep if Other == 0 
replace male = male * 100
replace urban_hk = urban_hk * 100

tab educ, gen(educ_)

forvalues i = 1(1)5{
replace educ_`i' = educ_`i' * 100 
}

**** Appendix Table A2 ****

outreg2 using "$path3/sum.xls" [aw = aw], replace sum(log) eqkeep(N mean sd) keep(unmarried HOMO HM male urban_hk age han educ_1 educ_2 educ_3 educ_4 educ_5) dec(3)
bys han:outreg2 using "$path3/sum_sub.xls" [aw = aw], replace sum(log) eqkeep(N mean sd) keep(unmarried HOMO HM male urban_hk age educ_1 educ_2 educ_3 educ_4 educ_5) dec(3)

keep if sex == 2 // women 

egen n_birth = rowtotal(numbirm numbirf)
replace n_birth = . if age > 45
outreg2 using "$path3/sum_birth.xls" [aw = aw], replace sum(log) eqkeep(N mean sd) keep(n_birth) dec(3)
bys han:outreg2 using "$path3/sum_birth_sub.xls" [aw = aw], replace sum(log) eqkeep(N mean sd) keep(n_birth) dec(3)
